//
//  DetailsWebViewController.m
//  ArtDog
//
//  Created by dllo on 16/9/10.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "DetailsWebViewController.h"
#import "HLMacro.h"
#import "ZWYNetTool.h"
#import "BannerTypeFourModel.h"
#import <WebKit/WebKit.h>

@interface DetailsWebViewController ()<WKNavigationDelegate>

@property (nonatomic, strong) BannerTypeFourModel *typeFourModel;
@property (nonatomic, strong) WKWebView *webView;

@end

@implementation DetailsWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createWebView];
    self.isHaveActivity = YES;
}

- (void)handleTypeFourData
{
    [ZWYNetTool GET:_urlString andBody:nil andHeader:HOSTHEADER andResponse:ZWYJSON andSuccessBlock:^(id result) {
        _typeFourModel = [BannerTypeFourModel modelWithDic:result[@"data"]];
        [self loadWebView:_typeFourModel.topicDetailUrl];
    } andFailureBlock:^(NSError *error) {
        NSLog(@"%@", error);
    }];
}

- (void)createWebView
{
    _webView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    [self.view addSubview:_webView];
    _webView.navigationDelegate = self;
}

- (void)loadWebView:(NSString *)webString
{
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:webString]];
    [_webView loadRequest:request];
    
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
{
    self.isHaveActivity = NO;
}

- (void)setUrlString:(NSString *)urlString
{
    _urlString = urlString;
    [self handleTypeFourData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
